<?php

namespace App\Logic;

use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\Request;


class Upload
{

    public static function base64($string){

        $imgdata=$string;


        $base64 = str_replace('data:image/jpeg;base64,', '' ,$imgdata);
        $base64 = str_replace('=', '',$base64);
        $img_len = strlen($base64);
        $file_size = $img_len - ($img_len/8)*2;
        $file_size = number_format(($file_size/1024),2).'kb';

        if($file_size >  5120){
            return e_msg(300028,'图片超出5M');
        }
        $base64_str = substr($imgdata, strpos($imgdata, ",")+1);
        $image=base64_decode($base64_str);
        $imgname=rand(1000,10000).time().'.png';
        Storage::put($imgname,$image);
        return s_msg('',$imgname);
    }

    public static function fileObject($request){
        //文件对象
        $path = $request->file('pic')->store('avatars');
        dd($path);

    }


}





